package emd24.telstudyresources;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * This class represents a question to be asked in the quiz.
 * 
 * @author Evan Dyke
 *
 */
public class Question {
	private final int NUM_ANSWERS = 5;
	private String questionText;
	private String[] answers;
	private int correctAnswer;
	private int selectedAnswer;
	private int questionNumber;
	boolean marked;
	/**
	 * Creates a question with fields specified in the constructor. This
	 * constructor will primarily be used for debugging
	 * 
	 * @param question String representing question
	 * @param answers String[] with answers to the question
	 * @param correctAnswer array index of correct answer
	 */
	public Question(String question, String[] answers,int correctAnswer){
		this.questionText = question;
		this.answers = answers;
		this.correctAnswer = correctAnswer;
		this.selectedAnswer = -1;
		this.marked = false;
	}
	/**
	 * Creates a question from a JSON Object.
	 * 
	 * @param question JSONObject representing question
	 * @throws JSONException 
	 */
	public Question(JSONObject question) throws JSONException{
		this.questionText = question.getString("questionText");
		JSONArray jsAnswers = question.getJSONArray("answers");
		this.answers = new String[this.NUM_ANSWERS];
		for(int ans = 0; ans < jsAnswers.length(); ans++){
			this.answers[ans] = jsAnswers.getString(ans);
		}
		this.correctAnswer = question.getInt("correctAnswer");
	}
	/**
	 * @return the questionText
	 */
	public String getQuestionText() {
		return questionText;
	}
	/**
	 * @param questionText the questionText to set
	 */
	public void setQuestionText(String questionText) {
		this.questionText = questionText;
	}
	/**
	 * @return the answers
	 */
	public String[] getAnswers() {
		return answers;
	}
	/**
	 * @param answers the answers to set
	 */
	public void setAnswers(String[] answers) {
		this.answers = answers;
	}
	/**
	 * @return the correctAnswer
	 */
	public int getCorrectAnswer() {
		return correctAnswer;
	}
	/**
	 * @param correctAnswer the correctAnswer to set
	 */
	public void setCorrectAnswer(int correctAnswer) {
		this.correctAnswer = correctAnswer;
	}
	/**
	 * @return the selectedAnswer
	 */
	public int getSelectedAnswer() {
		return selectedAnswer;
	}
	/**
	 * Sets the answer that the user chose.
	 * 
	 * @param selectedAnswer index of selected answer.
	 */
	public void setSelectedAnswer(int selectedAnswer) {
		this.selectedAnswer = selectedAnswer;
	}
	/**
	 * @return the marked
	 */
	public boolean isMarked() {
		return marked;
	}
	/**
	 * @param marked the marked to set
	 */
	public void setMarked(boolean marked) {
		this.marked = marked;
	}
	/**
	 * @return the questionNumber
	 */
	public int getQuestionNumber() {
		return questionNumber;
	}
	/**
	 * @param questionNumber the questionNumber to set
	 */
	public void setQuestionNumber(int questionNumber) {
		this.questionNumber = questionNumber;
	}
}
